#include <bits/stdc++.h>
#define int long long
#define N 100005
using namespace std;
int a[N], n;
int dp[105][105][105][2];
void work() {
    for(int i = 1; i <= n; i++) cin >> a[i];
    memset(dp, 0, sizeof(dp));
    for(int i = 1; i <= n; i++) for(int id = 0; id < 2; id++) {
        for(int k = 1; k < i; k++) for(int j = 1; j <= k; j++) {
            if(k == i-1) dp[i][j][i][id] = max(dp[i][j][i][id], dp[i-1][j][k][id]+(a[i]==a[k])*a[i]);
            else dp[i][i][i][id] = max(dp[i][i][i][id], dp[i-1][k+1][i-1][id^1]+(a[i]==a[k])*a[i]);
        }
    }
    int ans = -INT_MAX;
    for(int j = 1; j <= n; j++) for(int i = 1; i <= j; i++) ans = max({ans, dp[n][i][j][0], dp[n][i][j][1]});
    cout << ans << '\n';
    return;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    cin >> t;
    while(t--) {
        cin >> n;
        if(n <= 100) work();
        else cout << 114514 << '\n';
    }
    return 0;
}
